package com.assembly.util.tools;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;


import java.io.IOException;
import java.util.HashMap;

public class WxUtil {
    /***
     * 微信登录 获得 openId  https://api.weixin.qq.com/sns/jscode2session
     * @param wxCode  微信code
     * @param appid  微信 APPid
     * @param secret  微信 secret
     * @return
     * @throws Exception
     */
    public static JSONObject getUserWXLoginInfo(String wxCode, String appid, String secret) throws IOException {
        String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
        HashMap<String, Object> requestUrlParam = new HashMap<String,Object>();
        requestUrlParam.put("appid", appid);	//小程序 appI
        requestUrlParam.put("secret", secret);	//小程序 appSecret appSecret
        requestUrlParam.put("js_code", wxCode);	//登录时获取的 code
        requestUrlParam.put("grant_type", "authorization_code");	//授权类型，此处固定
        JSONObject jsonObject = JSON.parseObject(HttpUtil.doGet(requestUrl, requestUrlParam));
        return jsonObject;
    }



}